function page(flag) {

	if (flag == "first") {
		$currentpage = 1;
	} else if (flag == "last") {
		$currentpage = $totalpage;
	} else if (flag == "prev") {
		if ($currentpage - 1 <= 0) {
			return;
		}
		$currentpage--;
	} else if (flag == "next") {
		if ($currentpage + 1 > $totalpage) {
			return;
		}
		$currentpage++
	} else if (!isNaN(flag)) {
		if (flag > $totalpage || flag < 1) {
			alert("超出范围");
			return;
		}
		$currentpage = flag * 1;
	}
	$("#w-page").val($currentpage);
	$offset = ($currentpage - 1) * $pagesize;
	service.getBackuplogs(getBackupWrapper(), backupLogCB);
}
var backupLogCB = function(data) {
	var data = eval("(" + data + ")");
	var list = data.list.objList;
	$total = data.list.page.totalRecord;
	$totalpage = Math.ceil($total / $pagesize);
	$("#c-page").html($currentpage);
	$("#t-page").html($totalpage == 0 ? 1 : $totalpage);
	var content = "";
	for (var i = 0; i < list.length; i++) {
		var btime = list[i].beginTime;
		if (btime == 0) {
			btime = "---"
		} else {
			btime = new Date(btime).toLocaleString()
		}
		var etime = list[i].endTime;
		if (etime == 0 || etime == null) {
			etime = "---"
		} else {
			etime = new Date(etime).toLocaleString()
		}
		var caused = "";
		if (list[i].status == 0) {
			caused = "<font color='green'>" + list[i].caused + "</font>";
		} else {
			caused = "<font color='red'>" + list[i].caused + "</font>";
		}
		var usedSpace = list[i].usedSpace;
		if (list[i].usedSpace / 1024 > 1) {
			usedSpace = list[i].usedSpace / 1024.0;
			usedSpace = usedSpace.toFixed(2);
			usedSpace += "KB";
		} else {
			usedSpace += "B";
		}
		if (list[i].usedSpace / (1024 * 1024) > 1) {
			usedSpace = list[i].usedSpace / (1024.0 * 1024);
			usedSpace = usedSpace.toFixed(2);
			usedSpace += "MB";
		}
		if (list[i].usedSpace / (1024 * 1024 * 1024) > 1) {
			usedSpace = list[i].usedSpace / (1024.0 * 1024 * 1024);
			usedSpace = usedSpace.toFixed(2);
			usedSpace += "GB";
		}

		content = content + "<tr>"
				+ "<td>" + caused + "</td>"
				+ "<td>" + list[i].versionMajor + "." +list[i].versionMinor+ "</td>"
				+ "<td>" + usedSpace + "</td>"
				+ "<td>" + list[i].remark + "</td>"
				+ "<td>" + btime + "</td>"
				+ "<td>" + etime + "</td>";
		content = content + "</tr>";
	}
	if (list == undefined || list.length == 0) {
		content += "<tr><td colspan='6' style='text-align: center;'>暂无数据</td></tr>";
	}
	$("#blBody").html(content);
};

function getBackupWrapper() {
	var backupLog = {
		dsId : dsId,
	}
	var pages = {
		startPos : $currentpage,
		pageSize : $pagesize
	}
	var json = {};
	json["backupLog"] = backupLog;
	json["pages"] = pages;

	return json;
}

var service = new EbeimService();
var dsId = getUrlParam("dsId");
service.getBackuplogs(getBackupWrapper(), backupLogCB);